package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzSettingTechs;
import com.jy.adscm.operation.mscyb.bean.JqzzSettingTechs;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqzzSettingTechsMapper;
import com.jy.adscm.operation.mscyb.service.JqzzSettingTechsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.SjFile;
import com.jy.adscm.zltx.mapper.mysql.SjFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-21
 */
@Service
public class JqzzSettingTechsServiceImpl extends ServiceImpl<JqzzSettingTechsMapper, JqzzSettingTechs> implements JqzzSettingTechsService {
     @Autowired
    SjFileMapper sjFileMapper;
    @Override
    public List<SjFile> selectJqzzSettingTechsByPid(String pid) throws AdscmSystemException {
        List<SjFile> sjFiles=new ArrayList<>();

        //首先查询这有关联的id
        Wrapper<JqzzSettingTechs> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",pid);
        List<JqzzSettingTechs> jqbzSettingTechs = super.selectList(wrapper);
        if (jqbzSettingTechs!=null && jqbzSettingTechs.size()>0){
            for (JqzzSettingTechs jqzzSettingTech : jqbzSettingTechs) {
                SjFile sjFile = sjFileMapper.selectById(jqzzSettingTech.getCid());
                if (AdscmBaseUtils.getInstance().isNotEmpty(sjFile,null)){
                    sjFiles.add(sjFile) ;
                }
            }

        }
        return sjFiles;
    }

    @Override
    public List<SjFile> selectAll() throws AdscmSystemException {
        Wrapper<SjFile> wrapper =new EntityWrapper<>();
        wrapper.eq("fileGs","技术部机器");
        wrapper.eq("fileType","6");
        List<SjFile> sjFiles = sjFileMapper.selectList(wrapper);
        return sjFiles;
    }
}
